Ext.define('DCApp.view.catalog.ListController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.cataloglist',

    getSelectedItem: function(){
        return this.getView().getSelectionModel().getSelection()[0] || false;
    },

    onNew: function() {
    	this.redirectTo('catalogdetail/-1',false);
    },
    
    onOpenCatalog: function() {
    	var sel = this.getSelectedItem();
    	if(!sel)
    		return;
    	this.fireViewEvent('viewcatalog', this.getView(), sel);
    },
    
    onCatalogDblClick: function(view, rec) {
    	this.fireViewEvent('viewcatalog', this.getView(), rec);
    },
    
    onRefreshClick: function() {
        this.getView().getStore().load();
    },
    
    onRelCatalog: function() {
    	var ds = this.getView().getStore();
        var win = new Ext.window.Window({
        	width:500,
        	height:300,
        	layout:'fit',
        	modal:true,
        	viewModel: this.getViewModel(),
        	items:[{
        		 fieldName: 'id',
        		 xtype: 'multiselector',
        		 title:'选择期刊',
        		 store: ds,
                 search: {
                	 field: 'id',
                     store: {
                         model: 'Catalog'
                     }
                 }
        		}
        	],   
        	plain: true,
            headerPosition: 'bottom'
        });
        win.show();
    },
    
    onDelCatalog: function() {
		var sels = this.getView().getSelectionModel().getSelection();
		if (sels.length == 0) {
			Ext.MessageBox.alert('操作提示', '请先选择待删除的期刊', null, this);
			return;
		} else {
			Ext.MessageBox.confirm('确认删除', '您确定要删除选中的[' + sels.length + ']项?',
			function(btn, text) {
				if (btn != 'yes')
					return false;
	    		this.getView().getStore().getData().remove(sels);    				
			}, this);
		}    	
    }

});
